package com.shakespace.artofandroid.chapter02.binderpool

import com.shakespace.artofandroid.ISecurityCenter

class SecurityCenterImpl : ISecurityCenter.Stub() {

    private val SECRET_CODE = '^'

    override fun encrypt(content: String?): String {
        val charArray = content?.toCharArray()
        charArray?.apply {
            (charArray.indices).forEach {
                charArray[it] = (charArray[it].toInt() xor SECRET_CODE.toInt()).toChar()
            }
        }
        return if (charArray == null) {
            ""
        } else {
            String(charArray)
        }
    }

    override fun decrypt(password: String?): String {
        return encrypt(password)
    }

    companion object{
    }

}